var EBZoomLevel = Class.create( );
EBZoomLevel.prototype = {
	initialize: function(slotWidth, slotClassName, slotsNumber, time) {
		this.slotWidth = slotWidth;
		this.slotClassName = slotClassName;
		this.slotsNumber = slotsNumber;
		this.time = time;
	}
}

var EBZoomManager = Class.create( );
EBZoomManager.prototype = {
	initialize: function( ) {
		this.levels = new Array();
		this.current = 0;
		this.currentTime = null;
		this.currentDelta = 0;
	},
	
	newLevel: function(slotWidth, slotClassName, slotsNumber, time, defaultLevel) {
		this.levels[this.levels.length] = new EBZoomLevel(slotWidth, slotClassName, slotsNumber, time);
		if(defaultLevel) this.setCurrent(this.levels.length - 1);
	},
	
	setCurrent: function(index) {
		this.current = index;
		var timeParts = this.levels[this.current].time.split(' ');
		this.currentDelta = parseInt(timeParts[0]);
		this.currentTime = timeParts[1];
		//$('zoom-level').innerHTML = 'zoom: <strong>' + this.current + '</strong>';
	},
	
	getCurrent: function( ) {
		return this.levels[this.current];
	},
	
	doOut: function( ) {
		if(this.current < (this.levels.length - 1)) {
			this.setCurrent(this.current + 1);
			$RGE('browser').reset();
			return true;
		}
		return false;
	},
	
	doIn: function( ) {
		if(this.current > 0) {
			this.setCurrent(this.current - 1);
			$RGE('browser').reset();
			return true;
		}
		return false;
	},
	
	increaseDate: function(d) {
		return this.modifyDate(d);
	},
	
	decreaseDate: function(d) {
		return this.modifyDate(d, true);
	},
	
	modifyDate: function(d, decrease) {
		var cd = this.currentDelta;
		if(decrease) cd = -cd;
		if(this.currentTime == 'minutes') {
			d.setMinutes(d.getMinutes() + cd);
		}
		else if(this.currentTime == 'hours') {
			d.setHours(d.getHours() + cd);
		}
		else if(this.currentTime == 'days') {
			d.setDate(d.getDate() + cd);
		}
		else if(this.currentTime == 'months') {
			d.setMonth(d.getMonth() + cd);
			d.setDate(1);
		}
		else if(this.currentTime == 'years') {
			d.setFullYear(d.getFullYear() + cd);
			d.setDate(1);
			d.setMonth(0);
		}
		else {
			d.setDate(d.getDate() + cd);
		}
		return d;
	},
	
	initDate: function(d) {
		if(d==null) d = new Date();
		d.setSeconds(0);
		if(this.currentTime == 'months') {
			d.setDate(1);
			d.setMinutes(0);
			d.setHours(0);
		}
		else if(this.currentTime == 'years') {
			d.setDate(1);
			d.setMonth(0);
			d.setMinutes(0);
			d.setHours(0);			
		}
		else if(this.currentTime == 'days') {
			d.setMinutes(0);
			d.setHours(0);
		}
		else if(this.currentTime == 'hours') {
			d.setMinutes(0);
		}
		return d;
	}
}
